# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=ssma
_pkgname=SSMA
pkgver=215.2a2b6bd
pkgrel=9
pkgdesc='Simple Static Malware Analyzer.'
arch=('any')
groups=('blackarch' 'blackarch-malware')
url='https://github.com/secrary/SSMA'
license=('GPL-3.0-only')
depends=('python' 'python-pefile' 'python-magic' 'python-yara-python-dex'
         'ssdeep' 'python-elasticsearch' 'python-gitpython' 'python-pyelftools'
         'python-virustotal-api')
makedepends=('git')
source=("git+https://github.com/secrary/$_pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $_pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $_pkgname

  touch src/__init__.py
}

package() {
  cd $_pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  rm README.md

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname"

  chmod 755 "$pkgdir/usr/share/$pkgname/ssma.py"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python3 $pkgname.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

